<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/webpage/include/taglib.jsp" %>
<html class="ui-page-login">

<head>
    <%--    <meta charset="utf-8">--%>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta name="decorator" content="ani"/>
    <title>提报工单</title>
    <%@include file="/webpage/include/weixin.jsp" %>
    <style>
        .area {
            margin: 20px auto 0px auto;
        }

        .mui-input-group:first-child {
            margin-top: 20px;
        }

        .mui-input-group label {
            width: 22%;
        }

        .mui-input-row label ~ input,
        .mui-input-row label ~ select,
        .mui-input-row label ~ textarea {
            width: 70%;
        }

        .mui-checkbox input[type=checkbox],
        .mui-radio input[type=radio] {
            top: 6px;
        }

        .mui-content-padded {
            margin-top: 25px;
        }

        .mui-btn {
            padding: 10px;
        }
    </style>
    <script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script>
        var uiBase = $.uiBase;
        var page = {
            doMain:function(){
                return "${pageContext.request.contextPath}${fns:getApiPath()}";
            },
            init: function () {
                $('#account').val(localStorage['UserId']);
                //选择图片
                $('#selectImg').click(function () {

                    uiBase.warning('功能暂未开放!')
                })
                //提交功能
                $('#btnComit').click(function () {
                    var title = $('#title').val();
                    var user = $('#account').val();
                    var descr = $('#descr').val();
                    var selectGroup = $('#selectGroup').val();
                    var selectCustomerService = $('#selectCustomerService').val();
                    var workStatus = $('#workStatus').val();
                    var selectPriority = $('#selectPriority').val();
                    if (!title) {
                        uiBase.info('标题不能为空!');
                        return;
                    }
                    if (!user) {
                        uiBase.info('用户不能为空!')
                        // return;
                    }
                    if (!descr) {
                        uiBase.info('工作描述不能为空!')
                        return;
                    }
                    if (selectGroup == -1) {
                        uiBase.error('请选择受客服组!')
                        return;
                    }
                    if (selectCustomerService == -1) {
                        uiBase.info('请选择受理客服!')
                        return;
                    }
                    if (workStatus == -1) {
                        uiBase.info('请选择工作状态!')
                        return;
                    }
                    if (selectPriority == -1) {
                        uiBase.info('请选择优先级!')
                        return;
                    }
                    var data = {
                        'title': title,
                        'user': user,
                        'descr': descr,
                        'selectGroup': selectGroup,
                        'selectCustomerService': selectCustomerService,
                        'workStatus': workStatus,
                        'selectPriority': selectPriority
                    }
                    $.ajax({

                        url: '${ctxapi}/WXWork/getConfig?url=' + window.location.href,
                        dataType: 'json',
                        success: function (data) {
                            if (data.success = true) {
                                //微信配置
                                var wxtime = JSON.parse(data.msg).core.time;
                                var wxnonce = JSON.parse(data.msg).core.nonce;
                                var wxsignature = JSON.parse(data.msg).core.signature;
                                wx.config({
                                    debug: false,
                                    beta: true,
                                    appId: 'ww226c13b9e5425714',
                                    timestamp: wxtime,
                                    nonceStr: wxnonce,
                                    signature: wxsignature,
                                    jsApiList: [
                                        'checkJsApi',
                                        'onMenuShareAppMessage',
                                        'onMenuShareWechat',
                                        'onMenuShareTimeline',
                                        'shareAppMessage',
                                        'shareWechatMessage',
                                        'startRecord',
                                        'stopRecord',
                                        'onVoiceRecordEnd',
                                        'playVoice',
                                        'pauseVoice',
                                        'stopVoice',
                                        'uploadVoice',
                                        'downloadVoice',
                                        'chooseImage',
                                        'previewImage',
                                        'uploadImage',
                                        'downloadImage',
                                        'getNetworkType',
                                        'openLocation',
                                        'getLocation',
                                        'hideOptionMenu',
                                        'showOptionMenu',
                                        'hideMenuItems',
                                        'showMenuItems',
                                        'hideAllNonBaseMenuItem',
                                        'showAllNonBaseMenuItem',
                                        'closeWindow',
                                        'scanQRCode',
                                        'previewFile',
                                        'openEnterpriseChat',
                                        'selectEnterpriseContact',
                                        'onHistoryBack',
                                        'openDefaultBrowser',
                                    ],
                                    success: function (res) {
                                        // 回调

                                    },
                                    fail: function (res) {
                                        uiBase.info(res.errMsg)
                                    }
                                });
                                wx.ready(function () {
                                    wx.agentConfig({
                                        corpid: 'ww226c13b9e5425714', // 必填，企业微信的corpid，必须与当前登录的企业一致
                                        agentid: '1000015', // 必填，企业微信的应用id
                                        timestamp: JSON.parse(data.msg).agent.time, // 必填，生成签名的时间戳
                                        nonceStr: JSON.parse(data.msg).agent.nonce, // 必填，生成签名的随机串
                                        signature: JSON.parse(data.msg).agent.signature, // 必填，签名，见附录1
                                        jsApiList: ['chooseImage'], //必填
                                        success: function (res) {
                                            // 回调
                                            //调用审批流
                                            wx.invoke('thirdPartyOpenPage', {
                                                    "oaType": "10001", // String
                                                    "templateId": "b195f203e36e76283d429ae06be69816_941813075", // String
                                                    "thirdNo": new Date().getTime().toString(), // String
                                                    "extData": {
                                                        'fieldList': [{
                                                            'title': '工单类型',
                                                            'type': 'text',
                                                            'value': '提报工单',
                                                        },
                                                            {
                                                                'title': '标题',
                                                                'type': 'text',
                                                                'value': title,
                                                            },
                                                            {
                                                                'title': '发起人',
                                                                'type': 'text',
                                                                'value': user,
                                                            },
                                                            {
                                                                'title': '工作描述',
                                                                'type': 'text',
                                                                'value': descr,
                                                            },
                                                            {
                                                                'title': '受理客服组',
                                                                'type': 'text',
                                                                'value': $('#selectGroup').find("option:selected").text(),
                                                            },
                                                            {
                                                                'title': '受理客服',
                                                                'type': 'text',
                                                                'value': $('#selectCustomerService').find("option:selected").text(),
                                                            },
                                                            {
                                                                'title': '工作状态',
                                                                'type': 'text',
                                                                'value': $('#workStatus').find("option:selected").text(),
                                                            },
                                                            {
                                                                'title': '优先级',
                                                                'type': 'text',
                                                                'value': $('#selectPriority').find("option:selected").text()
                                                            }
                                                        ],
                                                    }
                                                },
                                                function (res) {
                                                    // 输出接口的回调信息
                                                    //alert(res)
                                                    console.log(res);
                                                });
                                        },
                                        fail: function (res) {
                                            if (res.errMsg.indexOf('function not exist') > -1) {
                                                uiBase.info('版本过低请升级')
                                            }
                                            else{
                                                uiBase.info(res.errMsg)
                                            }
                                        }
                                    });
                                })
                            }
                        },
                        error: function (err) {
                            alert(JSON.stringify(err))
                        }
                    })
                })


            },
            isWeiXin: function () {
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == 'micromessenger' || ua.match(/_SQ_/i) == '_sq_') {
                    return true;
                } else {
                    return false;
                }
            }
        }
        $(function () {
//				if(!page.isWeiXin())
//				{
//					location.href="src/error/wx.html"
//					return
//				}
            page.init()

        })
    </script>
</head>

<body>
<div class="mui-content">
    <div style="height: 30px;text-align: left;vertical-align: middle;margin-top: 10px;margin-left: 10px;">工作描述</div>
    <div class="mui-input-group">
        <div class="mui-input-row">
            <label style="vertical-align: middle;text-align: left;line-height: 30px;">标题
                <a style="color: red;">*</a>
            </label>
            <input id='title' type="text" style="line-height: 30px;text-align: left;vertical-align: middle;"
                   class="mui-input-clear mui-input" placeholder="请输入">
        </div>
        <div class="mui-input-row">
            <label style="vertical-align: middle;text-align: left;line-height: 30px;">发起人
            </label>
            <input id='account' type="text"
                   style="line-height: 30px;text-align: left;vertical-align: middle;right: 20px"
                   class="mui-input-clear mui-input" value="${UserId}" placeholder="请输入" readonly>
            <a class="mui-navigate-right"></a>
        </div>
        <div class="mui-input-row" style="height: 100px;">
            <div style="width: 200%;">
                <label style="vertical-align: middle;text-align: left;line-height: 30px;">工单描述
                    <a style="color: red;">*</a>
                </label>
            </div>
            <div>
                <input id='descr' type="text" style="line-height: 30px;text-align: left;vertical-align: middle;"
                       class="mui-input-clear mui-input" placeholder="请输入">
            </div>
        </div>
        <div class="mui-input-row" style="height: 120px;">
            <div style="width: 400% !important;">
                <label style="vertical-align: middle;text-align: left;line-height: 30px;">添加附件
                </label>
            </div>
            <div>

            </div>
            <div style="float: left;width: 100%;">
                <img id="selectImg" src="${ctxStatic}/common/images/iconfont-tianjia.png" width="50px" height="50px"
                     style="margin-left: 10px;"/>
            </div>
        </div>

    </div>
    <div style="height: 30px;text-align: left;vertical-align: middle;margin-top: 10px;margin-left: 10px;">工作性</div>
    <div class="mui-input-group">
        <div class="mui-input-row">
            <label style="vertical-align: middle;text-align: left;line-height: 30px;width: 35% !important;padding-top: 5px;">受理客服组
            </label>
            <select style="width: 65%;" id="selectGroup">
                <option value="-1">请选择</option>
                <option value="0" selected>北京华联精品超市有限公司支持组</option>
            </select>
            <a class="mui-navigate-right"></a>

        </div>
        <div class="mui-input-row">
            <label style="vertical-align: middle;text-align: left;line-height: 30px;width: 35% !important;padding-top: 5px;">受理客服
            </label>
            <select style="width: 65%;" id="selectCustomerService">
                <option value="-1">请选择</option>
                <option value="mw">马巍</option>
                <option value="dzy" selected>董振宇</option>
                <option value="lh">刘欢</option>
                <option value="pjc">平建超</option>
            </select>
            <a class="mui-navigate-right"></a>

        </div>
        <div class="mui-input-row">
            <label style="vertical-align: middle;text-align: left;line-height: 30px;width: 35% !important;padding-top: 5px;">工作状态
            </label>
            <select style="width: 65%;" id="workStatus">
                <option value="-1">请选择</option>
                <option value="0" selected>受理中</option>
                <option value="1">等待回复</option>
                <option value="2">己解决</option>
                <option value="3">己关闭</option>
            </select>
            <a class="mui-navigate-right"></a>

        </div>
        <div class="mui-input-row">
            <label style="vertical-align: middle;text-align: left;line-height: 30px;width: 35% !important;padding-top: 5px;">优先级
            </label>
            <select style="width: 65%;" id="selectPriority">
                <option value="-1">请选择</option>
                <option value="0" selected>低</option>
                <option value="1">中</option>
                <option value="2">高</option>
                <option value="3">紧急</option>
            </select>
            <a class="mui-navigate-right"></a>

        </div>

    </div>
</div>
<div>
    <div class="mui-content-padded">
        <button id='btnComit' class="mui-btn mui-btn-block mui-btn-primary">提交</button>
    </div>
</div>
</body>
</html>